<!DOCTYPE html>

<html lang="en">
  <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>表单（Forms） &mdash; Phalcon 3.0.1 文档</title>
    <meta name="keywords" content="php, phalcon, phalcon php, php framework, faster php framework">
    <link rel="stylesheet" type="text/css" href="http://cdn.staticfile.org/twitter-bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="/www/css/phalcon.min.css" />
    <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400' rel='stylesheet' type='text/css'>
    <link href="//fonts.googleapis.com/css?family=Merriweather:400,700" rel="stylesheet" type="text/css" />
    <!--
    EUROPE <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400&subset=latin-ext' rel='stylesheet' type='text/css'>
    GREEK <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400&subset=greek-ext' rel='stylesheet' type='text/css'>
    RUSSIA <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400&subset=cyrillic-ext,latin' rel='stylesheet' type='text/css'>
    -->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <link rel="stylesheet" href="../static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../static/docs.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.0.1',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>

    <script src="http://cdn.staticfile.org/jquery/1.8.1/jquery.min.js"></script>
    <script type="text/javascript" src="../static/docs.js"></script>
    <link rel="shortcut icon" href="../static/favicon.ico"/>
    <link rel="top" title="Phalcon 3.0.1 文档" href="../index.html" />
    <link rel="next" title="读取配置（Reading Configurations）" href="config.html" />
    <link rel="prev" title="验证（Validation）" href="validation.html" /> 
  </head>
  <body>

<header class="page-header">
    <nav class="navbar" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu-container">
                    <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                </button>
                <a class="navbar-brand phalcon-logo" href="/"><span itemprop="name" class="sr-only">Phalcon PHP</span></a>
            </div>

            <div class="collapse navbar-collapse navbar-right" id="main-menu-container">
                <ul class="nav navbar-nav main-menu">
                  <li class="first"><a href="//phalconphp.com/en/download" class="header-nav-link">Download</a></li>
                  <li><a href="//docs.phalconphp.com/en/latest/index.html" class="header-nav-link" target="_blank">Documentation</a></li>
                  <li><a href="//forum.phalconphp.com/" class="header-nav-link" target="_blank">Forum</a></li>
                  <li><a href="//blog.phalconphp.com/" class="header-nav-link" target="_blank">Blog</a></li>
                  <li><a href="//phalconist.com/" class="header-nav-link" target="_blank">Resources</a></li>
                  <li><a href="//phalconphp.com/en/about">About</a></li>
                  <li><div align="right">
                      <iframe src="https://ghbtns.com/github-btn.html?user=phalcon&amp;repo=cphalcon&amp;type=watch&amp;count=true&amp;size=large"
      allowtransparency="true" frameborder="0" scrolling="0" width="152px" height="30px"></iframe>
                    </div></li>
                </ul>
            </div>
        </div>
    </nav>
  </header>

<div class="heading">
    <div class="container">
        <div class="row">
            <h2>Documentation</h2>
        </div>
    </div>
</div>
    <div class="related">
      <ul>
        <li class="right" >
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="config.html" title="读取配置（Reading Configurations）"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="validation.html" title="验证（Validation）"
             accesskey="P">上一页</a> |</li>
        <li><a href="//phalconphp.com">Home</a> &raquo;</li>
        <li><a href="../index.html">Phalcon 3.0.1 文档</a> &raquo;</li> 
      </ul>
    </div>  

      <table width="100%" align="center" cellpadding="0" cellspacing="0">
        <tr>
      <td class="primary-box" width="25%" valign="top">
            <div>
            <div id="searchbox" style="">
                <!--<form class="search" action="http://readthedocs.org/search/project/" method="get">
                  <input type="search" name="q" size="25" placeholder="Search">
                  <input type="submit" value="Go">
                  <input type="hidden" name="selected_facets" value="project:">
                </form>-->
                <div style="width:200px;padding:10px">
                  <gcse:searchbox-only></gcse:searchbox-only>
                </div>
            </div>
            </div>
            <div style="padding:5px;padding-left:10px">
              <div id="carbonads-container">
                <div class="carbonad"><div id="azcarbon"></div>
                <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=phalconphpcom" id="_carbonads_js"></script>
                </div></div>
            </div>
            <h3><a href="../index.html">內容目录</a></h3>
            <ul>
<li><a class="reference internal" href="#">表单（Forms）</a><ul>
<li><a class="reference internal" href="#initializing-forms">初始化表单（Initializing forms）</a></li>
<li><a class="reference internal" href="#validation">验证（Validation）</a></li>
<li><a class="reference internal" href="#filtering">过滤（Filtering）</a></li>
<li><a class="reference internal" href="#forms-entities">表单与实体（Forms + Entities）</a></li>
<li><a class="reference internal" href="#form-elements">表单控件（Form Elements）</a></li>
<li><a class="reference internal" href="#event-callbacks">事件回调（Event Callbacks）</a></li>
<li><a class="reference internal" href="#rendering-forms">渲染表单（Rendering Forms）</a></li>
<li><a class="reference internal" href="#creating-form-elements">创建表单控件（Creating Form Elements）</a></li>
<li><a class="reference internal" href="#forms-manager">表单管理（Forms Manager）</a></li>
<li><a class="reference internal" href="#external-resources">外部资源（External Resources)</a></li>
</ul>
</li>
</ul>

            <h4>上一个主题</h4>
            <p class="topless"><a href="validation.html" title="上一章">&lt; 验证（Validation）</a></p>
            <h4>下一个主题</h4>
            <p class="topless"><a href="config.html" title="下一章">读取配置（Reading Configurations） &gt;</a></p>
            <h3>本页</h3>
            <ul class="this-page-menu">
              <li><a href="../sources/reference/forms.md" rel="nofollow">显示源代码</a></li>
            </ul>
        </td>
          <td class="second-box" valign="top">
            <div class="document">
                <div class="documentwrapper">
                  <div class="bodywrapper">
                    <div class="body" >
                      
  <div class="section" id="forms">
<h1>表单（Forms）<a class="headerlink" href="#forms" title="永久链接至标题">¶</a></h1>
<p>Phalcon中提供了 <code class="code docutils literal"><span class="pre">Phalcon\Forms</span></code> 组件以方便开发者创建和维护应用中的表单。</p>
<p>下面的例子中展示了基本的使用方法：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Forms\Form</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Forms\Element\Text</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Forms\Element\Select</span><span class="p">;</span>

<span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Form</span><span class="p">();</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
        <span class="s2">&quot;name&quot;</span>
    <span class="p">)</span>
<span class="p">);</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
        <span class="s2">&quot;telephone&quot;</span>
    <span class="p">)</span>
<span class="p">);</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">Select</span><span class="p">(</span>
        <span class="s2">&quot;telephoneType&quot;</span><span class="p">,</span>
        <span class="p">[</span>
            <span class="s2">&quot;H&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;Home&quot;</span><span class="p">,</span>
            <span class="s2">&quot;C&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;Cell&quot;</span><span class="p">,</span>
        <span class="p">]</span>
    <span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
<p>可在表单定义时穿插使用表单元素的字义：</p>
<div class="highlight-html+php"><div class="highlight"><pre><span class="nt">&lt;h1&gt;</span>
    Contacts
<span class="nt">&lt;/h1&gt;</span>

<span class="nt">&lt;form</span> <span class="na">method=</span><span class="s">&quot;post&quot;</span><span class="nt">&gt;</span>

    <span class="nt">&lt;p&gt;</span>
        <span class="nt">&lt;label&gt;</span>
            Name
        <span class="nt">&lt;/label&gt;</span>

        <span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$form</span><span class="o">-&gt;</span><span class="na">render</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">);</span> <span class="cp">?&gt;</span>
    <span class="nt">&lt;/p&gt;</span>

    <span class="nt">&lt;p&gt;</span>
        <span class="nt">&lt;label&gt;</span>
            Telephone
        <span class="nt">&lt;/label&gt;</span>

        <span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$form</span><span class="o">-&gt;</span><span class="na">render</span><span class="p">(</span><span class="s2">&quot;telephone&quot;</span><span class="p">);</span> <span class="cp">?&gt;</span>
    <span class="nt">&lt;/p&gt;</span>

    <span class="nt">&lt;p&gt;</span>
        <span class="nt">&lt;label&gt;</span>
            Type
        <span class="nt">&lt;/label&gt;</span>

        <span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$form</span><span class="o">-&gt;</span><span class="na">render</span><span class="p">(</span><span class="s2">&quot;telephoneType&quot;</span><span class="p">);</span> <span class="cp">?&gt;</span>
    <span class="nt">&lt;/p&gt;</span>



    <span class="nt">&lt;p&gt;</span>
        <span class="nt">&lt;input</span> <span class="na">type=</span><span class="s">&quot;submit&quot;</span> <span class="na">value=</span><span class="s">&quot;Save&quot;</span> <span class="nt">/&gt;</span>
    <span class="nt">&lt;/p&gt;</span>

<span class="nt">&lt;/form&gt;</span>
</pre></div>
</div>
<p>开发者可根据需要渲染HTML组件。 当使用:code:<cite>render()`函数时， phalcon内部会使用 :doc:`Phalcon\Tag &lt;../api/Phalcon_Tag&gt;</cite> 生成相应的html项，
第二个参数中可以对一些属性进行设置。</p>
<div class="highlight-html+php"><div class="highlight"><pre><span class="nt">&lt;p&gt;</span>
    <span class="nt">&lt;label&gt;</span>
        Name
    <span class="nt">&lt;/label&gt;</span>

    <span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$form</span><span class="o">-&gt;</span><span class="na">render</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;maxlength&quot;</span> <span class="o">=&gt;</span> <span class="mi">30</span><span class="p">,</span> <span class="s2">&quot;placeholder&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;Type your name&quot;</span><span class="p">]);</span> <span class="cp">?&gt;</span>
<span class="nt">&lt;/p&gt;</span>
</pre></div>
</div>
<p>HTML的属性也可以在创建时指定：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
        <span class="s2">&quot;name&quot;</span><span class="p">,</span>
        <span class="p">[</span>
            <span class="s2">&quot;maxlength&quot;</span>   <span class="o">=&gt;</span> <span class="mi">30</span><span class="p">,</span>
            <span class="s2">&quot;placeholder&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;Type your name&quot;</span><span class="p">,</span>
        <span class="p">]</span>
    <span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
<div class="section" id="initializing-forms">
<h2>初始化表单（Initializing forms）<a class="headerlink" href="#initializing-forms" title="永久链接至标题">¶</a></h2>
<p>从上面的例子我们可以看到表单项也可以在form对象初始化后进行添加。 当然开发者也可以对原有的Form类进行扩展：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Forms\Form</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Forms\Element\Text</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Forms\Element\Select</span><span class="p">;</span>

<span class="k">class</span> <span class="nc">ContactForm</span> <span class="k">extends</span> <span class="nx">Form</span>
<span class="p">{</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">initialize</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
            <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
                <span class="s2">&quot;name&quot;</span>
            <span class="p">)</span>
        <span class="p">);</span>

        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
            <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
                <span class="s2">&quot;telephone&quot;</span>
            <span class="p">)</span>
        <span class="p">);</span>

        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
            <span class="k">new</span> <span class="nx">Select</span><span class="p">(</span>
                <span class="s2">&quot;telephoneType&quot;</span><span class="p">,</span>
                <span class="nx">TelephoneTypes</span><span class="o">::</span><span class="na">find</span><span class="p">(),</span>
                <span class="p">[</span>
                    <span class="s2">&quot;using&quot;</span> <span class="o">=&gt;</span> <span class="p">[</span>
                        <span class="s2">&quot;id&quot;</span><span class="p">,</span>
                        <span class="s2">&quot;name&quot;</span><span class="p">,</span>
                    <span class="p">]</span>
                <span class="p">]</span>
            <span class="p">)</span>
        <span class="p">);</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>由于 <a class="reference internal" href="../api/Phalcon_Forms_Form.html"><em>Phalcon\Forms\Form</em></a> 实现了 <a class="reference internal" href="../api/Phalcon_Di_Injectable.html"><em>Phalcon\Di\Injectable</em></a> 接口，
所以开发者可以根据自己的需要访问应用中的服务。</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Forms\Form</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Forms\Element\Text</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Forms\Element\Hidden</span><span class="p">;</span>

<span class="k">class</span> <span class="nc">ContactForm</span> <span class="k">extends</span> <span class="nx">Form</span>
<span class="p">{</span>
    <span class="sd">/**</span>
<span class="sd">     * This method returns the default value for field &#39;csrf&#39;</span>
<span class="sd">     */</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">getCsrf</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">security</span><span class="o">-&gt;</span><span class="na">getToken</span><span class="p">();</span>
    <span class="p">}</span>

    <span class="k">public</span> <span class="k">function</span> <span class="nf">initialize</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="c1">// Set the same form as entity</span>
        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">setEntity</span><span class="p">(</span><span class="nv">$this</span><span class="p">);</span>

        <span class="c1">// Add a text element to capture the &#39;email&#39;</span>
        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
            <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
                <span class="s2">&quot;email&quot;</span>
            <span class="p">)</span>
        <span class="p">);</span>

        <span class="c1">// Add a text element to put a hidden CSRF</span>
        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
            <span class="k">new</span> <span class="nx">Hidden</span><span class="p">(</span>
                <span class="s2">&quot;csrf&quot;</span>
            <span class="p">)</span>
        <span class="p">);</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>相关的实体在初始化时添加到表单， 自定义的选项通过构造器传送：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Forms\Form</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Forms\Element\Text</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Forms\Element\Hidden</span><span class="p">;</span>

<span class="k">class</span> <span class="nc">UsersForm</span> <span class="k">extends</span> <span class="nx">Form</span>
<span class="p">{</span>
    <span class="sd">/**</span>
<span class="sd">     * Forms initializer</span>
<span class="sd">     *</span>
<span class="sd">     * @param Users $user</span>
<span class="sd">     * @param array $options</span>
<span class="sd">     */</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">initialize</span><span class="p">(</span><span class="nx">Users</span> <span class="nv">$user</span><span class="p">,</span> <span class="k">array</span> <span class="nv">$options</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="nv">$options</span><span class="p">[</span><span class="s2">&quot;edit&quot;</span><span class="p">])</span> <span class="p">{</span>
            <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
                <span class="k">new</span> <span class="nx">Hidden</span><span class="p">(</span>
                    <span class="s2">&quot;id&quot;</span>
                <span class="p">)</span>
            <span class="p">);</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
            <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
                <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
                    <span class="s2">&quot;id&quot;</span>
                <span class="p">)</span>
            <span class="p">);</span>
        <span class="p">}</span>

        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
            <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
                <span class="s2">&quot;name&quot;</span>
            <span class="p">)</span>
        <span class="p">);</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>在表单实例中必须要这样使用：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">UsersForm</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">Users</span><span class="p">(),</span>
    <span class="p">[</span>
        <span class="s2">&quot;edit&quot;</span> <span class="o">=&gt;</span> <span class="k">true</span><span class="p">,</span>
    <span class="p">]</span>
<span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="validation">
<h2>验证（Validation）<a class="headerlink" href="#validation" title="永久链接至标题">¶</a></h2>
<p>Phalcon表单组件可以和 <a class="reference internal" href="validation.html"><em>validation</em></a> 集成，以提供验证。 开发者要单独为每个html元素提供内置或自定义的验证器。</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Forms\Element\Text</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Validation\Validator\PresenceOf</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Validation\Validator\StringLength</span><span class="p">;</span>

<span class="nv">$name</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
    <span class="s2">&quot;name&quot;</span>
<span class="p">);</span>

<span class="nv">$name</span><span class="o">-&gt;</span><span class="na">addValidator</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">PresenceOf</span><span class="p">(</span>
        <span class="p">[</span>
            <span class="s2">&quot;message&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;The name is required&quot;</span><span class="p">,</span>
        <span class="p">]</span>
    <span class="p">)</span>
<span class="p">);</span>

<span class="nv">$name</span><span class="o">-&gt;</span><span class="na">addValidator</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">StringLength</span><span class="p">(</span>
        <span class="p">[</span>
            <span class="s2">&quot;min&quot;</span>            <span class="o">=&gt;</span> <span class="mi">10</span><span class="p">,</span>
            <span class="s2">&quot;messageMinimum&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;The name is too short&quot;</span><span class="p">,</span>
        <span class="p">]</span>
    <span class="p">)</span>
<span class="p">);</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span><span class="nv">$name</span><span class="p">);</span>
</pre></div>
</div>
<p>然后， 开发者可以根据用户的输入进行验证：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nv">$form</span><span class="o">-&gt;</span><span class="na">isValid</span><span class="p">(</span><span class="nv">$_POST</span><span class="p">))</span> <span class="p">{</span>
    <span class="nv">$messages</span> <span class="o">=</span> <span class="nv">$form</span><span class="o">-&gt;</span><span class="na">getMessages</span><span class="p">();</span>

    <span class="k">foreach</span> <span class="p">(</span><span class="nv">$messages</span> <span class="k">as</span> <span class="nv">$message</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">echo</span> <span class="nv">$message</span><span class="p">,</span> <span class="s2">&quot;&lt;br&gt;&quot;</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>验证器执行的顺序和注册的顺序一致。</p>
<p>默认情况下，所有的元素产生的消息是放在一起的， 所以开发者可以使用简单的foreach来遍历消息， 开发者可以按照自己的意愿组织输出：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">foreach</span> <span class="p">(</span><span class="nv">$form</span><span class="o">-&gt;</span><span class="na">getMessages</span><span class="p">(</span><span class="k">false</span><span class="p">)</span> <span class="k">as</span> <span class="nv">$attribute</span> <span class="o">=&gt;</span> <span class="nv">$messages</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">echo</span> <span class="s2">&quot;Messages generated by &quot;</span><span class="p">,</span> <span class="nv">$attribute</span><span class="p">,</span> <span class="s2">&quot;:&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span>

    <span class="k">foreach</span> <span class="p">(</span><span class="nv">$messages</span> <span class="k">as</span> <span class="nv">$message</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">echo</span> <span class="nv">$message</span><span class="p">,</span> <span class="s2">&quot;&lt;br&gt;&quot;</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>或获取指定元素的消息：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="nv">$messages</span> <span class="o">=</span> <span class="nv">$form</span><span class="o">-&gt;</span><span class="na">getMessagesFor</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">);</span>

<span class="k">foreach</span> <span class="p">(</span><span class="nv">$messages</span> <span class="k">as</span> <span class="nv">$message</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">echo</span> <span class="nv">$message</span><span class="p">,</span> <span class="s2">&quot;&lt;br&gt;&quot;</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="filtering">
<h2>过滤（Filtering）<a class="headerlink" href="#filtering" title="永久链接至标题">¶</a></h2>
<p>表单元素可以在进行验证前先进行过滤， 开发者可以为每个元素设置过滤器：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Forms\Element\Text</span><span class="p">;</span>

<span class="nv">$name</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
    <span class="s2">&quot;name&quot;</span>
<span class="p">);</span>

<span class="c1">// Set multiple filters</span>
<span class="nv">$name</span><span class="o">-&gt;</span><span class="na">setFilters</span><span class="p">(</span>
    <span class="p">[</span>
        <span class="s2">&quot;string&quot;</span><span class="p">,</span>
        <span class="s2">&quot;trim&quot;</span><span class="p">,</span>
    <span class="p">]</span>
<span class="p">);</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span><span class="nv">$name</span><span class="p">);</span>



<span class="nv">$email</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
    <span class="s2">&quot;email&quot;</span>
<span class="p">);</span>

<span class="c1">// Set one filter</span>
<span class="nv">$email</span><span class="o">-&gt;</span><span class="na">setFilters</span><span class="p">(</span>
    <span class="s2">&quot;email&quot;</span>
<span class="p">);</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span><span class="nv">$email</span><span class="p">);</span>
</pre></div>
</div>
<blockquote class="highlights">
<div>Learn more about filtering in Phalcon by reading the <a class="reference internal" href="filter.html"><em>Filter documentation</em></a>.</div></blockquote>
</div>
<div class="section" id="forms-entities">
<h2>表单与实体（Forms + Entities）<a class="headerlink" href="#forms-entities" title="永久链接至标题">¶</a></h2>
<p>我们可以把 model/collection/plain 设置到表单对象中， 这样 phalcon 会自动的设置表单元素的值：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="nv">$robot</span> <span class="o">=</span> <span class="nx">Robots</span><span class="o">::</span><span class="na">findFirst</span><span class="p">();</span>

<span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Form</span><span class="p">(</span><span class="nv">$robot</span><span class="p">);</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
        <span class="s2">&quot;name&quot;</span>
    <span class="p">)</span>
<span class="p">);</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span>
        <span class="s2">&quot;year&quot;</span>
    <span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
<p>在表单渲染时如果表单项未设置默认值， phalcon会使用对象实体值作为默认值：</p>
<div class="highlight-html+php"><div class="highlight"><pre><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$form</span><span class="o">-&gt;</span><span class="na">render</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">);</span> <span class="cp">?&gt;</span>
</pre></div>
</div>
<p>开发者可以使用下面的方式验证表单及利用用户的输入来设置值：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">bind</span><span class="p">(</span><span class="nv">$_POST</span><span class="p">,</span> <span class="nv">$robot</span><span class="p">);</span>

<span class="c1">// Check if the form is valid</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$form</span><span class="o">-&gt;</span><span class="na">isValid</span><span class="p">())</span> <span class="p">{</span>
    <span class="c1">// Save the entity</span>
    <span class="nv">$robot</span><span class="o">-&gt;</span><span class="na">save</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
</div>
<p>也可以使用一个简单的类做为对象实体进行参数传递：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">class</span> <span class="nc">Preferences</span>
<span class="p">{</span>
    <span class="k">public</span> <span class="nv">$timezone</span> <span class="o">=</span> <span class="s2">&quot;Europe/Amsterdam&quot;</span><span class="p">;</span>

    <span class="k">public</span> <span class="nv">$receiveEmails</span> <span class="o">=</span> <span class="s2">&quot;No&quot;</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
<p>使用此类做为对象实体，这样可以使用此类中的值作为表单的默认值：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Form</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">Preferences</span><span class="p">()</span>
<span class="p">);</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">Select</span><span class="p">(</span>
        <span class="s2">&quot;timezone&quot;</span><span class="p">,</span>
        <span class="p">[</span>
            <span class="s2">&quot;America/New_York&quot;</span>  <span class="o">=&gt;</span> <span class="s2">&quot;New York&quot;</span><span class="p">,</span>
            <span class="s2">&quot;Europe/Amsterdam&quot;</span>  <span class="o">=&gt;</span> <span class="s2">&quot;Amsterdam&quot;</span><span class="p">,</span>
            <span class="s2">&quot;America/Sao_Paulo&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;Sao Paulo&quot;</span><span class="p">,</span>
            <span class="s2">&quot;Asia/Tokyo&quot;</span>        <span class="o">=&gt;</span> <span class="s2">&quot;Tokyo&quot;</span><span class="p">,</span>
        <span class="p">]</span>
    <span class="p">)</span>
<span class="p">);</span>

<span class="nv">$form</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">Select</span><span class="p">(</span>
        <span class="s2">&quot;receiveEmails&quot;</span><span class="p">,</span>
        <span class="p">[</span>
            <span class="s2">&quot;Yes&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;Yes, please!&quot;</span><span class="p">,</span>
            <span class="s2">&quot;No&quot;</span>  <span class="o">=&gt;</span> <span class="s2">&quot;No, thanks&quot;</span><span class="p">,</span>
        <span class="p">]</span>
    <span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
<p>实体中也可以使用getters, 这样可以给开发者更多的自由， 当然也会洽使开发稍麻烦一些，不过这是值得的：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">class</span> <span class="nc">Preferences</span>
<span class="p">{</span>
    <span class="k">public</span> <span class="nv">$timezone</span><span class="p">;</span>

    <span class="k">public</span> <span class="nv">$receiveEmails</span><span class="p">;</span>



    <span class="k">public</span> <span class="k">function</span> <span class="nf">getTimezone</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="s2">&quot;Europe/Amsterdam&quot;</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="k">public</span> <span class="k">function</span> <span class="nf">getReceiveEmails</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="s2">&quot;No&quot;</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="form-elements">
<h2>表单控件（Form Elements）<a class="headerlink" href="#form-elements" title="永久链接至标题">¶</a></h2>
<p>Phalcon提供了一些内置的html元素类， 所有这些元素类仅位于 <a class="reference internal" href="../api/Phalcon_Forms_Element.html"><em>Phalcon\Forms\Element</em></a> 命名空间下：</p>
</div>
<div class="section" id="event-callbacks">
<h2>事件回调（Event Callbacks）<a class="headerlink" href="#event-callbacks" title="永久链接至标题">¶</a></h2>
<p>当扩展表单时， 我们可以在表单类中实现验证前操作及验证后操作：</p>
<div class="highlight-html+php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Forms\Form</span><span class="p">;</span>

<span class="k">class</span> <span class="nc">ContactForm</span> <span class="k">extends</span> <span class="nx">Form</span>
<span class="p">{</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">beforeValidation</span><span class="p">()</span>
    <span class="p">{</span>

    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="rendering-forms">
<h2>渲染表单（Rendering Forms）<a class="headerlink" href="#rendering-forms" title="永久链接至标题">¶</a></h2>
<p>开发者对表单的渲染操作有完全的控制， 下面的的例子展示了如何使用标准方法渲染html元素：</p>
<div class="highlight-html+php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="o">&lt;</span><span class="nx">form</span> <span class="nx">method</span><span class="o">=</span><span class="s2">&quot;post&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;?</span><span class="nx">php</span>

        <span class="c1">// Traverse the form</span>
        <span class="k">foreach</span> <span class="p">(</span><span class="nv">$form</span> <span class="k">as</span> <span class="nv">$element</span><span class="p">)</span> <span class="p">{</span>
            <span class="c1">// Get any generated messages for the current element</span>
            <span class="nv">$messages</span> <span class="o">=</span> <span class="nv">$form</span><span class="o">-&gt;</span><span class="na">getMessagesFor</span><span class="p">(</span>
                <span class="nv">$element</span><span class="o">-&gt;</span><span class="na">getName</span><span class="p">()</span>
            <span class="p">);</span>

            <span class="k">if</span> <span class="p">(</span><span class="nb">count</span><span class="p">(</span><span class="nv">$messages</span><span class="p">))</span> <span class="p">{</span>
                <span class="c1">// Print each element</span>
                <span class="k">echo</span> <span class="s1">&#39;&lt;div class=&quot;messages&quot;&gt;&#39;</span><span class="p">;</span>

                <span class="k">foreach</span> <span class="p">(</span><span class="nv">$messages</span> <span class="k">as</span> <span class="nv">$message</span><span class="p">)</span> <span class="p">{</span>
                    <span class="k">echo</span> <span class="nv">$message</span><span class="p">;</span>
                <span class="p">}</span>

                <span class="k">echo</span> <span class="s2">&quot;&lt;/div&gt;&quot;</span><span class="p">;</span>
            <span class="p">}</span>

            <span class="k">echo</span> <span class="s2">&quot;&lt;p&gt;&quot;</span><span class="p">;</span>

            <span class="k">echo</span> <span class="s1">&#39;&lt;label for=&quot;&#39;</span><span class="p">,</span> <span class="nv">$element</span><span class="o">-&gt;</span><span class="na">getName</span><span class="p">(),</span> <span class="s1">&#39;&quot;&gt;&#39;</span><span class="p">,</span> <span class="nv">$element</span><span class="o">-&gt;</span><span class="na">getLabel</span><span class="p">(),</span> <span class="s2">&quot;&lt;/label&gt;&quot;</span><span class="p">;</span>

            <span class="k">echo</span> <span class="nv">$element</span><span class="p">;</span>

            <span class="k">echo</span> <span class="s2">&quot;&lt;/p&gt;&quot;</span><span class="p">;</span>
        <span class="p">}</span>

    <span class="cp">?&gt;</span>

    <span class="nt">&lt;input</span> <span class="na">type=</span><span class="s">&quot;submit&quot;</span> <span class="na">value=</span><span class="s">&quot;Send&quot;</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;/form&gt;</span>
</pre></div>
</div>
<p>或是在登录表单中重用表单类：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Forms\Form</span><span class="p">;</span>

<span class="k">class</span> <span class="nc">ContactForm</span> <span class="k">extends</span> <span class="nx">Form</span>
<span class="p">{</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">initialize</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="c1">// ...</span>
    <span class="p">}</span>

    <span class="k">public</span> <span class="k">function</span> <span class="nf">renderDecorated</span><span class="p">(</span><span class="nv">$name</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="nv">$element</span>  <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get</span><span class="p">(</span><span class="nv">$name</span><span class="p">);</span>

        <span class="c1">// Get any generated messages for the current element</span>
        <span class="nv">$messages</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">getMessagesFor</span><span class="p">(</span>
            <span class="nv">$element</span><span class="o">-&gt;</span><span class="na">getName</span><span class="p">()</span>
        <span class="p">);</span>

        <span class="k">if</span> <span class="p">(</span><span class="nb">count</span><span class="p">(</span><span class="nv">$messages</span><span class="p">))</span> <span class="p">{</span>
            <span class="c1">// Print each element</span>
            <span class="k">echo</span> <span class="s1">&#39;&lt;div class=&quot;messages&quot;&gt;&#39;</span><span class="p">;</span>

            <span class="k">foreach</span> <span class="p">(</span><span class="nv">$messages</span> <span class="k">as</span> <span class="nv">$message</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">echo</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">flash</span><span class="o">-&gt;</span><span class="na">error</span><span class="p">(</span><span class="nv">$message</span><span class="p">);</span>
            <span class="p">}</span>

            <span class="k">echo</span> <span class="s2">&quot;&lt;/div&gt;&quot;</span><span class="p">;</span>
        <span class="p">}</span>

        <span class="k">echo</span> <span class="s2">&quot;&lt;p&gt;&quot;</span><span class="p">;</span>

        <span class="k">echo</span> <span class="s1">&#39;&lt;label for=&quot;&#39;</span><span class="p">,</span> <span class="nv">$element</span><span class="o">-&gt;</span><span class="na">getName</span><span class="p">(),</span> <span class="s1">&#39;&quot;&gt;&#39;</span><span class="p">,</span> <span class="nv">$element</span><span class="o">-&gt;</span><span class="na">getLabel</span><span class="p">(),</span> <span class="s2">&quot;&lt;/label&gt;&quot;</span><span class="p">;</span>

        <span class="k">echo</span> <span class="nv">$element</span><span class="p">;</span>

        <span class="k">echo</span> <span class="s2">&quot;&lt;/p&gt;&quot;</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>视图中：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">echo</span> <span class="nv">$element</span><span class="o">-&gt;</span><span class="na">renderDecorated</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">);</span>

<span class="k">echo</span> <span class="nv">$element</span><span class="o">-&gt;</span><span class="na">renderDecorated</span><span class="p">(</span><span class="s2">&quot;telephone&quot;</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="creating-form-elements">
<h2>创建表单控件（Creating Form Elements）<a class="headerlink" href="#creating-form-elements" title="永久链接至标题">¶</a></h2>
<p>除了可以使用phalcon提供的html元素以外， 开发者还可以使用自定义的html元素：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Forms\Element</span><span class="p">;</span>

<span class="k">class</span> <span class="nc">MyElement</span> <span class="k">extends</span> <span class="nx">Element</span>
<span class="p">{</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">render</span><span class="p">(</span><span class="nv">$attributes</span> <span class="o">=</span> <span class="k">null</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="nv">$html</span> <span class="o">=</span> <span class="c1">// ... Produce some HTML</span>

        <span class="k">return</span> <span class="nv">$html</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="forms-manager">
<h2>表单管理（Forms Manager）<a class="headerlink" href="#forms-manager" title="永久链接至标题">¶</a></h2>
<p>此组件为开发者提供了一个表单管理器， 可以用来注册表单，此组件可以使用服务容器来访问：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Forms\Manager</span> <span class="k">as</span> <span class="nx">FormsManager</span><span class="p">;</span>

<span class="nv">$di</span><span class="p">[</span><span class="s2">&quot;forms&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="k">function</span> <span class="p">()</span> <span class="p">{</span>
    <span class="k">return</span> <span class="k">new</span> <span class="nx">FormsManager</span><span class="p">();</span>
<span class="p">};</span>
</pre></div>
</div>
<p>表单被添加到表单管理器， 然后设置了唯一的名字：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="nv">$this</span><span class="o">-&gt;</span><span class="na">forms</span><span class="o">-&gt;</span><span class="na">set</span><span class="p">(</span>
    <span class="s2">&quot;login&quot;</span><span class="p">,</span>
    <span class="k">new</span> <span class="nx">LoginForm</span><span class="p">()</span>
<span class="p">);</span>
</pre></div>
</div>
<p>使用唯一名， 我们可以在应用的任何地方访问到表单：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="nv">$loginForm</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">forms</span><span class="o">-&gt;</span><span class="na">get</span><span class="p">(</span><span class="s2">&quot;login&quot;</span><span class="p">);</span>

<span class="k">echo</span> <span class="nv">$loginForm</span><span class="o">-&gt;</span><span class="na">render</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="external-resources">
<h2>外部资源（External Resources)<a class="headerlink" href="#external-resources" title="永久链接至标题">¶</a></h2>
<ul class="simple">
<li><a class="reference external" href="http://vokuro.phalconphp.com">Vökuró</a> 是一个使用表单构建器来创建和维护表单的示例 [<a class="reference external" href="https://github.com/phalcon/vokuro">Github</a>]</li>
</ul>
</div>
</div>


                    </div>
                  </div>
                </div>
            </div>
          </td>
        </tr>
      </table>
    <div class="related">
      <ul>
        <li class="right" >
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="config.html" title="读取配置（Reading Configurations）"
             >下一页</a> |</li>
        <li class="right" >
          <a href="validation.html" title="验证（Validation）"
             >上一页</a> |</li> 
      </ul>
    </div>

      <div class="prefooter">
  <div class="container">
      <div class="row">
          <div class="col-sm-3 text-right">
              <span>Follow along:</span>
          </div>
          <div class="col-sm-6 text-center">
              <a href="https://twitter.com/phalconphp" alt="Twitter" class="btn-social btn-social-twitter"><i class="icon-twitter"></i></a>
              <a href="https://www.facebook.com/pages/Phalcon-Framework/134230726685897" alt="Facebook" class="btn-social btn-social-facebook"><i class="icon-facebook"></i></a>
              <a href="https://plus.google.com/102376109340560896457" alt="Google+" class="btn-social btn-social-googleplus"><i class="icon-googleplus"></i></a>
              <a href="https://github.com/phalcon/cphalcon" alt="Github" class="btn-social btn-social-github"><i class="icon-github"></i></a>
          </div>
          <div class="col-sm-3">
          </div>
      </div>
  </div>

</div>
<footer class="footer">
    <div class="container">
        <div class="row">
            <div class="col-xs-4 col-sm-3">
                <h4>Download</h4>
                <ul>
                    <li><a href="/download">Installing Phalcon PHP</a></li>
                    <li><a href="http://docs.phalconphp.com/en/latest/index.html" class="header-nav-link" target="_blank">Documentation</a></li>
                    <li><a href="http://api.phalconphp.com">API</a></li>
                    <li><a href="http://docs.phalconphp.com/en/latest/reference/tutorial.html">Tutorial</a></li>
                    <li><a href="http://docs.phalconphp.com/en/latest/reference/tutorial.html#sample-applications">Sample Applications</a></li>
                </ul>
            </div>
            <div class="col-xs-4 col-sm-3">
                <h4>Community</h4>
                <ul>
                    <li><a href="http://forum.phalconphp.com/" class="header-nav-link" target="_blank">Forum</a></li>
                    <li><a href="https://github.com/phalcon/cphalcon">GitHub</a></li>
                    <li><a href="https://github.com/phalcon/cphalcon/issues">Issue Tracker</a></li>
                    <li><a href="http://stackoverflow.com/questions/tagged/phalcon">Stack Overflow</a></li>
                    <li><a href="/en/testimonials">Testimonials</a></li>
                    <li><a href="http://builtwith.phalconphp.com/">Built with Phalcon</a></li>
                    <li><a href="http://store.phalconphp.com/">Store</a></li>
                </ul>
            </div>
            <div class="col-xs-4 col-sm-2">
                <h4>About</h4>
                <ul>
                    <li><a class="link-black" href="http://blog.phalconphp.com/">Blog</a></li>
                    <li><a href="/en/about">About</a></li>
                    <li><a href="/en/team">Team</a></li>
                    <li><a href="/en/roadmap">Roadmap</a></li>
                    <li><a href="/en/donate">Donate</a></li>
                    <li><a href="/en/consulting">Consulting</a></li>
                    <li><a href="/en/hosting">Hosting</a></li>
                </ul>
            </div>
            <div id="license-spaccer" class="visible-xs"></div>
            <div id="license-wrapper" class="col-xs-12 col-sm-4">
                <p class="license">
                    Phalcon is an open-source PHP framework <br>built as a C-extension. It is available under the <br>
                    <a href="http://opensource.org/licenses/BSD-3-Clause" target="_blank">new BSD License</a>.
                    <br>
                    <br>
                    Except where otherwise noted, content on this site is licensed under the
                    <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License.</a>
                </p>
            </div>
        </div>
    </div>
</footer>

    </div>
    <script type="text/javascript">
    $(window).on("load", function(){
      var cx = '009733439235723428699:lh9ltjgvdz8';
      var gcse = document.createElement('script');
      gcse.type = 'text/javascript';
      gcse.async = true;
      gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx;
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(gcse, s);
    });
    </script>

  </body>
</html>